<?php
    header("Content-Type:text/html; charset=utf-8");

    //获取到客户端的账号密码
    $loginName = $_POST['loginName'];
    $password = $_POST['password'];
    //在数据库里进行查询
    $con = mysqli_connect("127.0.0.1","root","","xxy");
    //判断是否已经建立链接
    if(!$con){
        printf("Can't connect to MySQL Server. Errorcode: %s ",mysqli_connect_error());
        exit;
    }
    //根据查询结果进行响应
    $sql = "SELECT * FROM employee WHERE loginName='$loginName' and password='$password'";
    //响应一个结果
    $result = mysqli_query($con,$sql);
    //获取这个结果
    if($row = mysqli_fetch_array($result)){
        //怎么拿到数据
        //$row代表的是一行数据
        $user = array(
            "username" => $row["username"],
            "password" => $row["password"]
        );
        session_start();
        $_SESSION["user"]=$user;
        header("Refresh:3;url=index.php");
    }else{
        //登录失败，用户名或密码错误　
                header("Refresh:3;url=../page/login.html");
                echo "登录失败 3s 后跳转到登录页面";
    }
?>